package com.fundboss.display;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.market.MarketConfig;

public class MarketParamPanel  extends JPanel{

	public MarketParamPanel(final MarketConfig config){
		setLayout(new GridLayout(0,2));
		
		JLabel title = new JLabel("Market");
		title.setFont(new Font("Arial",Font.BOLD,18));
		add(title);
		add(new JLabel(""));
		
		
		add(new JLabel("Risk free"));
		final JComboBox riskFree = new JComboBox(new Object[]{"0%","1%","2%","3%","4%","5%","6%"});
		add(riskFree);
		riskFree.setSelectedItem("3%");
		config.setRiskFreeRate(.03);
		
		
		riskFree.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				
		        Number number =AssetsParamPanel.getPercent(riskFree.getSelectedItem());
		        // 1.2345
		        double oldRiskFree= config.getInitialRiskFreeRate();
		        double newRiskFree =((Double)number);
		        config.setRiskFreeRate(newRiskFree);
		        config.setShareCashflowRate(config.getShareCashflowRate()+(newRiskFree-oldRiskFree));
			    
			}
		});
		
		
		
		add(new JLabel("Initial Equity risk premium"));
		final JComboBox equityPremium = new JComboBox(new Object[]{"0%","1%","2%","3%","4%","5%","6%"});
		add(equityPremium);
		equityPremium.setSelectedItem("2%");
		config.setShareCashflowRate(config.getInitialRiskFreeRate()+.02);
		
		equityPremium.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				
			        Number number =AssetsParamPanel.getPercent(equityPremium.getSelectedItem());
			        // 1.2345
			        config.setShareCashflowRate(((Double)number)+config.getInitialRiskFreeRate());
			    
			}
		});
		
		add(new JLabel("ERP used in calcs"));
		final JComboBox erp = new JComboBox(new Object[]{MarketConfig.ERP_FIXED,MarketConfig.ERP_OBSERVED});
		erp.setSelectedItem(MarketConfig.ERP_FIXED);
		config.setErpCalculation(MarketConfig.ERP_FIXED);
		add(erp);
		erp.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String option = (String) erp.getSelectedItem();
				config.setErpCalculation(option);
			}
		});
		
		//AM: vol adjustment not supported at the moment.
		add(new JLabel("Asset Vol Adjustment"));
		final JComboBox volAdjust = new JComboBox(new Object[]{
				MarketConfig.VolatilityAdjustment.NO_ADJUSTMENT,
				MarketConfig.VolatilityAdjustment.ADJUSTED,
				MarketConfig.VolatilityAdjustment.FIXED});
		volAdjust.setSelectedItem(MarketConfig.VolatilityAdjustment.NO_ADJUSTMENT);
		add(volAdjust);
		volAdjust.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				config.setVolatilityAdjustment((MarketConfig.VolatilityAdjustment)volAdjust.getSelectedItem());
			}
		});
		
	}
}
